package com.xueyi.aixihu.reqeust;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.xueyi.aixihu.exception.SzException;
import com.xueyi.aixihu.reqeust.base.Add;
import com.xueyi.aixihu.reqeust.base.Update;
import com.xueyi.aixihu.status.SystemCode;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 * @authoer:hxs
 * @createDate:2022/8/16
 * @description: 新增、修改文章对象
 */
@Data
public class DtNewsReq {
    /**
     * id
     */
    private Integer id;
    private String idStr;

    /**
     * 父级id
     */
    private Integer cid;

    /**
     * 标题
     */
    @NotBlank(message = "请输入文章标题", groups = {Update.class, Add.class})
    @Length(min = 0, max = 60, message = "标题长度过长", groups = {Update.class, Add.class})
    private String title;

    /**
     * 排序
     */

    private Integer paixuTem;

    /**
     * 图片
     */
//    @NotBlank(message = "请上传封面图片")
    private String img;
    private String thumb;

    /**
     * 内容
     */
    @NotBlank(message = "请输入文章内容", groups = {Update.class, Add.class})
    private String content;

    /**
     * 创建时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTimeNew;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private String createTime;

    /**
     * 地区id
     */
    private Integer fromToAreaId;

    /**
     * 文章显示状态
     */
    private Integer status;

    private Integer systemTypeId;

    private Integer contentType;

    /**
     * 指定角色审核
     */
    private String roleIds;


//    public void format() throws SzException {
//        try {
//            this.cid = Integer.parseInt(this.cidStr.trim());
//            if (!StringUtils.isBlank(this.paixu)) {
//                this.paixuTem = Integer.parseInt(this.paixu.trim());
//            }
//        } catch (Exception e) {
//            throw new SzException(SystemCode.QUERY_CHECK_ERROR, "参数类型错误");
//        }
//
//        this.fromToAreaId = this.cid;
//    }

//    public void formatId() throws SzException {
//
//        if (StringUtils.isBlank(this.idStr)) {
//            throw new SzException(SystemCode.QUERY_CHECK_ERROR, "请选择需要修改到文章");
//        }
//
//        try {
//            this.id = Integer.parseInt(this.idStr.trim());
//        } catch (Exception e) {
//            throw new SzException(SystemCode.QUERY_CHECK_ERROR, "参数类型错误");
//        }
//    }
}
